package main;

/**
 * Created by twer on 3/3/14.
 */
public class DiamondExercises {

    public void IsoscelesTriangle(int sideLength){
        String triangle = getTop(sideLength);
        System.out.println("Isosceles triangle:");
        System.out.print(triangle);
    }

    public void Diamond(int sideLength){
        String diamond = getTop(sideLength);
        diamond += getBottom(sideLength);
        System.out.println("Diamond:");
        System.out.print(diamond);
    }

    public void DiamondWithName(int sideLength, String name){
        String diamond = "";
        for(int i=1; i<sideLength; i++){
            diamond += getBlank(sideLength - i) + getAsterisk(i) + "\n";
        }
        diamond += name + "\n";
        diamond += getBottom(sideLength);
        System.out.println("Diamond with name:");
        System.out.print(diamond);
    }

    private String getTop(int sideLength) {
        String diamond = "";
        for(int i=1; i<=sideLength; i++){
            diamond += getBlank(sideLength - i) + getAsterisk(i) + "\n";
        }
        return diamond;
    }

    private String getBottom(int sideLength) {
        String bottom = "";
        for(int i=sideLength+1; i<2*sideLength; i++){
            bottom += getBlank(i - sideLength) + getAsterisk(2*sideLength - i) + "\n";
        }
        return bottom;
    }

    private String getBlank(int blankCount) {
        String blanks = "";
        while (blankCount > 0) {
            blanks += " ";
            blankCount --;
        }
        return blanks;
    }

    private String getAsterisk(int vertical) {
        String asterisks = "";
        int asteriskCount = 2 * vertical - 1;
        for(int i=0; i<asteriskCount; i++){
            asterisks += "*";
        }
        return asterisks;
    }
}